package com.doctor.utils.network;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.doctor.comm.MyApplication;

/**
 * Created by chemin on 2016/7/5.
 */
public class ConfigInfoHelper {


//    /**
//     * @return 返回用户手机信息的字符串
//     */
//    public static String getConfigInfo() {
//        StringBuilder phoneInfoBuilder = new StringBuilder();
//        phoneInfoBuilder.append(NetConfig.APP_TYPE)
//                .append(NetConfig.APP_VERSION)
//                .append(getAppVersion())
//                .append(NetConfig.DEVICE_ID)
//                .append(getDeviceId())
//                .append(NetConfig.DEVICE_MODEL)
//                .append(Build.MODEL)
//                .append(NetConfig.DEVICE_INFO)
//                .append(Build.MODEL)
//                .append(NetConfig.CHANNEL)
//                .append(getChannel())
//                .append(NetConfig.TARGET_LIFE);
//        return phoneInfoBuilder.toString();
//    }




    /**
     * @return 返回当前版本号
     */
    public static String getAppVersion() {
        PackageManager packageManager = MyApplication.getInstance().getPackageManager();
        String appVersion = null;
        try {
            PackageInfo info = packageManager.getPackageInfo(MyApplication.getInstance().getPackageName(), 0);
            appVersion = info.versionName;
            if (appVersion == null || appVersion.length() == 0) {
                return "1.0";
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return "1.0";
        }
        return appVersion;
    }

    /**
     * 获取设备ID
     *
     * @return
     */
    public static String getDeviceId() {
        TelephonyManager telephonyManager = (TelephonyManager) MyApplication.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
        String deviceId = telephonyManager.getDeviceId();
        //        LogUtils.w("--->deviceId" + deviceId);
        if (TextUtils.isEmpty(deviceId)) {
            return "error";
        }
        return deviceId;
    }

}
